//For a Chrome add on to allow downloading from Soundcloud or YouTube
//by right clicking on an appropriate link

//include SoundCloud's library
function loadjsFile (filename){
	var fileref = document.createElement('script');
	fileref.setAttribute("type","text/javascript");
	fileref.setAttribute("src", filename);
}

//call if the link is to SoundCloud
function sc(e){
	
	SC.initialize({
		client_id: this.ClientID
	});
	
	//stream track id 293
	SC.stream(e.linkUrl, function(sound){
		sound.play();
	});
}

//call if the link is to YouTube
function yt(e){
	
}

function genericOnClick(e){
	window.open("http://offliberty.com");
	console.log("liberated!");
}

//load Soundcloud API
loadjsFile("http://connect.soundcloud.com/sdk.js");

propertiesSC = new Object();
propertiesSC.targetUrlPatterns = new Array("http://soundcloud.com/*");
propertiesSC.title = "Liberate!";
propertiesSC.contexts = ["link"];
propertiesSC.onclick = sc;
propertiesSC.id = "soundcloud";

var id = chrome.contextMenus.create(propertiesSC);
console.log(id);

/*
propertiesYT = new Object();
propertiesYT.targetUrlPatterns = new Array("http://www.youtube.com/*");
propertiesYT.title = "Liberate!";
propertiesYT.contexts = ["link"];
propertiesYT.onclick = yt;
propertiesYT.id = "youtube";

var id = chrome.contextMenus.create(propertiesYT);
console.log(id)
*/